import Loading from './Loading.vue';
import Vue from 'vue';

// 获取Loading组件的构造函数
// 通过vue.extend()新建一个子类LoadingConstructor
// loading是对应的loading的模板
const LoadingConstructor = Vue.extend(Loading);

const serve = ()=>{
    // 创建loading实例
    let loadingInstance = new LoadingConstructor();
    // 将组件挂载到指定的元素
    loadingInstance.$mount(document.createElement('div'));
    // 将组件挂载的元素添加到body元素下
    document.body.appendChild(loadingInstance.$el);
    // Vue.nextTick(()=>{
        loadingInstance.visible = true;
    // }) 

    Vue.nextTick(()=>{
        setTimeout(() => {
            loadingInstance.visible = false;
        },1000);
    })
    
    return loadingInstance;
}

export default serve;